package com.cxg.fairy.ec.detail;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cxg.fairy.ec.main.personal.order.OrderListDelegate;
import com.cxg.fairy.ec.main.personal.order.OrderListEntryDelegate;
import com.cxg.fairy.util.log.LatteLogger;

import java.util.ArrayList;

/**
 * Created by CFairy
 */

public class OrderListTabPagerAdapter extends FragmentStatePagerAdapter {

    private final ArrayList<String> TAB_TITLES = new ArrayList<>();

    private OrderListEntryDelegate mDelegate = null;

    public OrderListTabPagerAdapter(FragmentManager fm, JSONObject data, OrderListEntryDelegate delegate) {
        super(fm);
        mDelegate = delegate;
        final JSONArray tabs = new JSONArray();
        tabs.add(0, "全部订单");
        tabs.add(1, "待付款");
        tabs.add(2, "待配送");
        tabs.add(3, "待收货");
        tabs.add(4, "待评价");
        tabs.add(5, "轻松退");
        final int size = tabs.size();
        for (int i = 0; i < size; i++) {
            final String name = tabs.get(i).toString();
            TAB_TITLES.add(name);
        }
    }

    @Override
    public Fragment getItem(int position) {
        if (position == 0) {
//            return ImageDelegate.create(PICTURES.get(0));
            return OrderListDelegate.create(0,mDelegate);
        } else if (position == 1) {
            return OrderListDelegate.create(1,mDelegate);
        } else if (position == 2) {
            return OrderListDelegate.create(2,mDelegate);
        } else if (position == 3) {
            return OrderListDelegate.create(3,mDelegate);
        } else if (position == 4) {
            return OrderListDelegate.create(4,mDelegate);
        } else if (position == 5) {
            return OrderListDelegate.create(5,mDelegate);
        }
        return null;
    }

    @Override
    public int getCount() {
        return TAB_TITLES.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return TAB_TITLES.get(position);
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}
